package com.akk.module.avs.service;

import com.akk.module.avs.entity.*;
import com.akk.module.avs.mapper.AvsYbLoanRecordMapper;
import com.akk.module.avs.mapper.AvsYbLoanUserMapper;
import com.akk.module.avs.mapper.dao.AvsYbLoanRecordDao;
import com.akk.module.avs.mapper.dao.AvsYbLoanUserDao;
import com.akk.module.avs.model.response.AvsYbLoanRecordRes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AvsYbLoanRecordService {

    @Autowired
    private AvsYbLoanRecordMapper recordMapper;

    @Autowired
    private AvsYbLoanRecordExample recordExample;

    @Autowired
    private AvsYbLoanUserMapper userMapper;

    @Autowired
    private AvsYbLoanUserExample userExample;

    @Autowired
    private AvsYbLoanRecordDao recordDao;

    @Autowired
    private AvsYbLoanUserDao userDao;

    public List<AvsYbLoanRecordRes> findByParams(Map params){
        return recordDao.selectWithLoanName(params);
    }

    public AvsYbLoanRecord findById(Long recordId){
        return recordMapper.selectByPrimaryKey(recordId);
    }

    public void save(AvsYbLoanRecord record){
        recordMapper.insert(record);
    }

    public void delete(Long recordId){
        recordMapper.deleteByPrimaryKey(recordId);
    }

    public AvsYbLoanUser findUserById(Long userId){
        return userMapper.selectByPrimaryKey(userId);
    }

    public List<AvsYbLoanUser> findByIdCard(String idCard){
        userExample.clear();
        userExample.createCriteria().andIdCardEqualTo(idCard);
        return userMapper.selectByExample(userExample);
    }

    public void saveUser(AvsYbLoanUser user){
        userMapper.insert(user);
    }

    public AvsYbLoanUser saveUserWithReturn(AvsYbLoanUser user){
        userDao.saveReturn(user);
        return user;
    }

    public void update(AvsYbLoanRecord record){
        recordMapper.updateByPrimaryKey(record);
    }

}
